package cn.com.se.sharepictrue.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.ArrayList;
import java.util.List;

import cn.com.se.sharepictrue.R;
import cn.com.se.sharepictrue.activity.ShowPictureActivity;
import cn.com.se.sharepictrue.business.ImageLoader;
import cn.com.se.sharepictrue.utils.SystemUtils;

/**
 * Created by KIDNG on 2015/11/30.
 */
public class ShareImgAdapter extends BaseRecyclerAdapter<String> {
    private Context mContext;
    private ArrayList<String> mList;

    public ShareImgAdapter(Context context) {
        super(context);
        mContext = context;
    }

    public ShareImgAdapter(Context context, List<String> data) {
        super(context, data);
        mList = new ArrayList<String>(data);
        mContext = context;
    }

    @Override
    public void onBindViewHolder(final RecyclerHolder holder, String data) {
        ImageView img = (ImageView) holder.itemView;
        int padding = SystemUtils.convertDIP2PX(getContext(), 16);
        ViewGroup.LayoutParams params = img.getLayoutParams();
        params.width = SystemUtils.getScreenWidth(getContext()) / 3 - padding;
        params.height = params.width;
        img.setLayoutParams(params);
        ImageLoader.getInstance(getContext()).load(img, data, R.mipmap.ic_placeholder);
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext,ShowPictureActivity.class);
                Bundle bundle = new Bundle();
                bundle.putStringArrayList(ShowPictureActivity.IMAGES_KEY, mList);
                bundle.putInt(ShowPictureActivity.IMAGE_POSITION_KEY, holder.getLayoutPosition());
                intent.putExtras(bundle);
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getLayoutRes(int viewType) {
        return R.layout.item_share_list_img;
    }
}
